﻿<?php
//include_once '../../lib/profile.class.php';
    //$conn = @mysql_connect(HOST, USERNAME, PASSWORD) OR die('Impossibile connettersi al database.<br>Contatta l\'amministratore ' );
    //$conn = @mysql_connect('127.0.0.1', "root", "") OR die('Impossibile connettersi al database.<br>Contatta l\'amministratore ' );
	//@mysql_select_db('db_lucciola', $conn) OR die('Impossibile selezionare il database ' . 'db_lucciola' . '.<br>Contatta l\'amministratore ');
    $conn = @mysql_connect('localhost', "coccovac_dev", "c0cc0v4c3") OR die('Impossibile connettersi al database.<br>Contatta l\'amministratore ' );
	@mysql_select_db('coccovac_dev', $conn) OR die('Impossibile selezionare il database ' . 'coccovac_dev' . '.<br>Contatta l\'amministratore ');
		
   //$db = new mysqli('127.0.0.1', 'root' ,'', 'db_lucciola');
	if(isset($_POST['queryString'])) 
	{		
			$queryString = $conn->mysql_real_escape_string($_POST['queryString']);			
			if(strlen($queryString) >0) {
			
				$query = $conn->query(MyQuery()." and ( nome LIKE '%$queryString%') LIMIT 10");
				if($query) {
				echo '<ul>';
					while ($result = $query ->fetch_object()) {
	         			echo '<li onClick="fill(\''.addslashes($result->art_title).'\');">'.MyHighlight($queryString, $result->art_introtext, $result->art_title, $result->art_id, $result->cat_title).'</li>';
	         		}
				echo '</ul>';
					
				} else {
					echo 'OOPS we had a problem :(';
				}
			} else {
				// do nothing				
			}
	} else {
		echo 'There should be no direct access to this script!';
	}
return ;	

function MyQuery() {
	$query = 'SELECT id_citta, nome, provincia FROM citta WHERE 1=1'; 
	return $query;
}


function MyHighlight($pChars, $pText, $pTitle, $pID, $pCatTitle) {
// Remove all html tags...
$stringa=strip_tags($pText); 

// Highlight the title
//$pTitle=preg_replace("/$pChars/i", '<span style="background-color:#FFFFCC; color:black">'.$pTitle.'</span>', $Title);

// Create the link
$doclink='<div class="mylink1"><a href="http://www.byman.it/?program=index_document&document='.$pID.'">'.$pTitle.'</a>'.'</div>';
$category="<strong>".$pCatTitle."</strong>";
$header='<table style="width:100%;"><tr><td style="width:50%;text-align:left;">'.$doclink.'<b></b>'.$category.'</td>';

// Highlight the string
$stringa=preg_replace("/$pChars/i", '<td style="width:50%;text-align:right;"><span style="background-color:#9e1aaa; color:000">'.$pChars.'</span></td>', $stringa);

// Add Title
$stringa=$header.'<br />'.$stringa'</tr></table>';


return $stringa;

}
?>


